package com.example.forum.services.impl;

import com.example.forum.dao.ArticleReplyMapper;
import com.example.forum.model.ArticleReply;
import com.example.forum.services.ArticleReplyService;
import com.example.forum.services.ArticleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ArticleReplyServiceImpl implements ArticleReplyService {

    @Resource
    private ArticleReplyMapper articleReplyMapper;

    @Resource
    private ArticleService articleService;


    /**
     * 创建一文章的评论，需要文章id
     * @param articleReply
     */
    @Override
    public void create(ArticleReply articleReply) {
        //查询要回复的文章是否存在，如果不存就抛出异常
        //填充默认数据
        articleReply.setState((byte) 0); //状态
        articleReply.setDeleteState((byte) 0); //是否状态
        articleReply.setLikeCount(0); //点赞数量
        //时间
        Date date = new Date();
        articleReply.setCreateTime(date); //创建时间
        articleReply.setUpdateTime(date); //更新时间
        //写入数据
        articleReplyMapper.insertSelective(articleReply);
        //更新文章的回复数量
        articleService.addReplyCount(articleReply.getArticleId());
    }

}
